home *** CD-ROM | disk | FTP | other *** search
- {RANDOM NUMBER GENERATOR GARY CURTIS NEWPORT
-
- PURPOSE : To generate a pseudorandom number in the open interval, (0,1).
-
- ALGORITHM : The linear congruential method is used. See M. J. Merchant,
- FORTRAN 77: Language and Style, Belmont: Wadsworth, 1981,
- p. 254.
-
- USE : The following global declaration is necessary:
-
- VAR seed : long_integer;
-
- Include RANDNUMS after program declarations. At the beginning
- of the program, insert the following:
-
- SET_RANDOM(seed);
-
- This seeds the random number generator, which can be called
- as needed, in the following way:
-
- x := RANDOM(seed);
-
- (Where x is any declared real variable.)
-
- }
-
- procedure SET_RANDOM ( VAR seed : long_integer);
-
- CONST
- factor = 8191; { must be >= 0 and < 262139 }
-
- BEGIN {SET_RANDOM}
- seed := CLOCK mod factor
- END; {SET_RANDOM}
-
- function RANDOM ( VAR seed : long_integer): real;
-
- CONST
- j = 5243;
- k = 55397;
- m = 262139;
-
- BEGIN {RANDOM}
- seed := ((seed * j) + k) mod m;
- RANDOM := (seed + 0.5)/m
- END; {RANDOM}
- əəəəəəəəəəəəə